package cn.gcyl.module.biz.controller.app;

import cn.gcyl.framework.apilog.core.annotation.ApiAccessLog;
import cn.gcyl.framework.common.pojo.CommonResult;
import cn.gcyl.framework.common.pojo.PageParam;
import cn.gcyl.framework.common.pojo.PageResult;
import cn.gcyl.framework.common.util.object.BeanUtils;
import cn.gcyl.framework.excel.core.util.ExcelUtils;
import cn.gcyl.module.biz.controller.admin.platforminformation.vo.AppPlatformInformationListReqVO;
import cn.gcyl.module.biz.controller.admin.platforminformation.vo.AppPlatformInformationPageReqVO;
import cn.gcyl.module.biz.controller.admin.specialmeeting.vo.AppSpecialMeetingListReqVO;
import cn.gcyl.module.biz.controller.admin.specialmeeting.vo.AppSpecialMeetingPageReqVO;
import cn.gcyl.module.biz.controller.admin.thirdpartyinformation.vo.AppThirdPartyInformationListReqVO;
import cn.gcyl.module.biz.controller.admin.thirdpartyinformation.vo.ThirdPartyInformationPageReqVO;
import cn.gcyl.module.biz.controller.admin.usersubscriptionwordslog.vo.UserSubscriptionWordsLogPageReqVO;
import cn.gcyl.module.biz.controller.admin.usersubscriptionwordslog.vo.UserSubscriptionWordsLogRespVO;
import cn.gcyl.module.biz.controller.admin.usersubscriptionwordslog.vo.UserSubscriptionWordsLogSaveReqVO;
import cn.gcyl.module.biz.controller.app.DTO.AppUserSubscriptionWordsVO;
import cn.gcyl.module.biz.dal.dataobject.platforminformation.PlatformInformationDO;
import cn.gcyl.module.biz.dal.dataobject.specialmeeting.SpecialMeetingDO;
import cn.gcyl.module.biz.dal.dataobject.thirdpartyinformation.ThirdPartyInformationDO;
import cn.gcyl.module.biz.dal.dataobject.usersubscriptionwordslog.UserSubscriptionWordsLogDO;
import cn.gcyl.module.biz.dal.mysql.specialmeeting.SpecialMeetingMapper;
import cn.gcyl.module.biz.dal.mysql.thirdpartyinformation.ThirdPartyInformationMapper;
import cn.gcyl.module.biz.dal.mysql.useractionlog.UserActionLogMapper;
import cn.gcyl.module.biz.dal.mysql.usersubscriptionwordslog.UserSubscriptionWordsLogMapper;
import cn.gcyl.module.biz.service.alliancemembers.AllianceMembersService;
import cn.gcyl.module.biz.service.carouselimage.CarouselImageService;
import cn.gcyl.module.biz.service.marketinformation.MarketInformationService;
import cn.gcyl.module.biz.service.platforminformation.PlatformInformationService;
import cn.gcyl.module.biz.service.specialmeeting.SpecialMeetingService;
import cn.gcyl.module.biz.service.thirdpartyinformation.ThirdPartyInformationService;
import cn.gcyl.module.biz.service.usersubscriptionwordslog.UserSubscriptionWordsLogService;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import static cn.gcyl.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static cn.gcyl.framework.common.pojo.CommonResult.success;
import static cn.gcyl.framework.web.core.util.WebFrameworkUtils.getLoginUserId;

@Tag(name = "app - 用户订阅词记录")
@RestController
@RequestMapping("/biz/user-subscription-words-log")
@Validated
public class AppUserSubscriptionWordsLogController {

    @Resource
    private UserSubscriptionWordsLogService userSubscriptionWordsLogService;
    @Resource
    private UserSubscriptionWordsLogMapper subscriptionWordsLogMapper;
    @Resource
    private SpecialMeetingMapper specialMeetingMapper;
    @Resource
    private AllianceMembersService allianceMembersService;
    @Resource
    private PlatformInformationService platformInformationService;
    @Resource
    private SpecialMeetingService specialMeetingService;
    @Resource
    private ThirdPartyInformationMapper thirdPartyInformationMapper;
    @Resource
    private MarketInformationService marketInformationService;
    @Resource
    private UserActionLogMapper userActionLogMapper;
    @Resource
    private CarouselImageService carouselImageService;

    @PostMapping("/create")
    @Operation(summary = "创建用户订阅词记录")
//    @PreAuthorize("@ss.hasPermission('biz:user-subscription-words-log:create')")
    public CommonResult<Long> createUserSubscriptionWordsLog(@Valid @RequestBody UserSubscriptionWordsLogSaveReqVO createReqVO) {
        return success(userSubscriptionWordsLogService.createUserSubscriptionWordsLog(createReqVO));
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除用户订阅词记录")
    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('biz:user-subscription-words-log:delete')")
    public CommonResult<Boolean> deleteUserSubscriptionWordsLog(@RequestParam("id") Long id) {
        userSubscriptionWordsLogService.deleteUserSubscriptionWordsLog(id);
        return success(true);
    }
    @DeleteMapping("/clearAll")
    @Operation(summary = "清空用户订阅词记录")
    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('biz:user-subscription-words-log:delete')")
    public CommonResult<Boolean> clearAllUserSubscriptionWordsLog() {
        Long loginUserId = getLoginUserId();
        subscriptionWordsLogMapper.delete(
                new LambdaQueryWrapper<UserSubscriptionWordsLogDO>().eq(UserSubscriptionWordsLogDO::getUserId, loginUserId)
        );
        return success(true);
    }

    @GetMapping("/getUserSubscriptionWordsLogList")
    @Operation(summary = "获得用户订阅词记录list")
//    @PreAuthorize("@ss.hasPermission('biz:user-subscription-words-log:query')")
    public CommonResult<List<UserSubscriptionWordsLogDO>> getUserSubscriptionWordsLogList() {
        Long loginUserId = getLoginUserId();
            List<UserSubscriptionWordsLogDO> userSubscriptionWordsLogDOS = subscriptionWordsLogMapper.selectList(
                    new LambdaQueryWrapper<UserSubscriptionWordsLogDO>().eq(UserSubscriptionWordsLogDO::getUserId, loginUserId)
                            .orderByDesc(UserSubscriptionWordsLogDO::getCreateTime)
            );
            return success(userSubscriptionWordsLogDOS);
    }
//    @PostMapping("/getUserSubscriptionList")
//    @Operation(summary = "获得用户订阅list")
////    @PreAuthorize("@ss.hasPermission('biz:user-subscription-words-log:query')")
//    public CommonResult<List<AppUserSubscriptionWordsVO>> getUserSubscriptionList(@Valid @RequestBody UserSubscriptionWordsLogPageReqVO reqVO) {
//        Long loginUserId = getLoginUserId();
//        ArrayList<String> objects = new ArrayList<>();
//        List<UserSubscriptionWordsLogDO> userSubscriptionWordsLogDOS = subscriptionWordsLogMapper.selectList(
//                new LambdaQueryWrapper<UserSubscriptionWordsLogDO>().eq(UserSubscriptionWordsLogDO::getUserId, loginUserId)
//        );
//        if (ObjectUtil.isNotEmpty(userSubscriptionWordsLogDOS)){
//            for (UserSubscriptionWordsLogDO userSubscriptionWordsLogDO : userSubscriptionWordsLogDOS) {
//                objects.add(userSubscriptionWordsLogDO.getSubscriptionWord());
//            }
//        }
//        if (reqVO.getColumns().equals("项目采购商机")||reqVO.getColumns().equals("项目分包商机")||reqVO.getColumns().equals("集中招募商机")){
//            AppPlatformInformationListReqVO platformInformationListReqVO = new AppPlatformInformationListReqVO();
//            platformInformationListReqVO.setTitleType(reqVO.getColumns());
//            platformInformationListReqVO.setArea(reqVO.getArea());
//            platformInformationListReqVO.setTitle(objects.toArray(new String[0]));
//            List<PlatformInformationDO> appPlatformInformationList = platformInformationService.AppPlatformInformationListReqVO(platformInformationListReqVO);
//            List<AppUserSubscriptionWordsVO> bean = BeanUtils.toBean(appPlatformInformationList, AppUserSubscriptionWordsVO.class);
//            return success(bean);
//        }else if (reqVO.getColumns().equals("专场会议")){
//            AppSpecialMeetingListReqVO appSpecialMeetingListReqVO = new AppSpecialMeetingListReqVO();
//            appSpecialMeetingListReqVO.setMeetingName(objects.toArray(new String[0]));
//            appSpecialMeetingListReqVO.setArea(reqVO.getArea());
//            List<SpecialMeetingDO> appSpecialMeetingList = specialMeetingMapper.getAppSpecialMeetingList(appSpecialMeetingListReqVO);
//            List<AppUserSubscriptionWordsVO> bean = BeanUtils.toBean(appSpecialMeetingList, AppUserSubscriptionWordsVO.class);
//            return success(bean);
//        }else if (reqVO.getColumns().equals("招标")||reqVO.getColumns().equals("采购")||reqVO.getColumns().equals("中标")){
//            AppThirdPartyInformationListReqVO appThirdPartyInformationListReqVO = new AppThirdPartyInformationListReqVO();
//            appThirdPartyInformationListReqVO.setArea(reqVO.getArea());
//            appThirdPartyInformationListReqVO.setTitle(objects.toArray(new String[0]));
//            List<ThirdPartyInformationDO> appThirdPartyInformationList = thirdPartyInformationMapper.getAppThirdPartyInformationList(appThirdPartyInformationListReqVO);
//            List<AppUserSubscriptionWordsVO> bean = BeanUtils.toBean(appThirdPartyInformationList, AppUserSubscriptionWordsVO.class);
//            return success(bean);
//        }
//        return success(null);
//    }

}